package com.unmarshaller.propertiesunmarshaller.transformer;

import java.lang.reflect.Field;

import javax.xml.crypto.dsig.TransformException;

import com.unmarshaller.propertiesunmarshaller.ITransformer;


/**
 * 枚举类型转换赋值
 * @author hongxiao.z
 * @date	2013-10-21
 */
public class EnumTransformer implements ITransformer
{
	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Override
	public void transformer(Field field, String value)throws TransformException
	{
		Class<? extends Enum> clazz = (Class<? extends Enum>) field.getType();

		try
		{
			field.set(null, Enum.valueOf(clazz, value));
		}
		catch (Exception e)
		{
			throw new TransformException("value:" + value + " invalid, is not transformer --- " + field.getType().getSimpleName() + " to " + field.getName());
		}
	}
	
}
